/**
 * Copyright (c) 2015 XiaoYuanShenQi. All rights reserved.

 * Author: newma
 * Date: 6/29/15
 * Descript: 使用log4js来做服务器的日志记录

 *  Modified:
 */

var log4js = require('log4js');

var logInit = function() {
    console.log('init logger module...');

    log4js.configure({
        appenders: [
            { type: 'console' }, //控制台输出
            {
                type: 'file', //文件输出
                filename: 'logs/xysq_server.log',
                maxLogSize: 1024,
                backups: 3,
                category: 'xysq'
            }
        ]
        //replaceConsole: true   // 替换console.log
    });

    var logger = log4js.getLogger('xysq');
    logger.setLevel('DEBUG');
    return logger;
}

var logger = logInit();
if (!logger.hasOwnProperty('use')) {
    logger.use = function(app) {
      app.use(log4js.connectLogger(logger, {level: 'auto', format: ':method :url'}));
    };
}

module.exports = logger;
